package com.gotloop.services;

import java.util.Date;
import java.util.List;

import com.gotloop.dto.CommentDTO;
import com.gotloop.dto.LoopDTO;

/**
 * Loop Service, provides methods to find, save, modify and delete loops.
 * @author jibhaine
 *
 */
public interface LoopService {

	/**
	 * find a Loop by its title.
	 * @param loopUrl loop title
	 * @return a Loop, null if not found
	 */
	LoopDTO findLoopByTitle(String loopUrl);
	
	/**
	 * find the last published loops, ordered by creationDate.
	 * @param startIndex the first index.
	 * @param nbOfLoops number of loops to retrieve.
	 * @return a list of Loops
	 */
	List<LoopDTO> findLastLoops(int startIndex, int nbOfLoops);
	
	/**
	 * find loops by author.
	 * @param authorName User author name.
	 * @param startIndex the first index.
	 * @param nbOfLoops number of loops to retrieve.
	 * @return a list of Loops
	 */
	List<LoopDTO> findLoopsByAuthor(String authorName, int startIndex, int nbOfLoops);
	
	/**
	 * find Loops by tag.
	 * @param tag the tag contained in Loop.tags
	 * @param startIndex the first index.
	 * @param nbOfLoops number of loops to retrieve.
	 * @return a list of Loops
	 */
	List<LoopDTO> findLoopsByTag(String tag, int startIndex, int nbOfLoops);
	
	/**
	 * find loops by follower. (the loops made by User he follows.).
	 * @param followerName name of follower user.
	 * @param startIndex the first index.
	 * @param nbOfLoops number of loops to retrieve.
	 * @return a list of Loops
	 */
	List<LoopDTO> findLoopsForFollower(String followerName, int startIndex, int nbOfLoops);
	
	/**
	 * Find loops by dates.
	 * @param startDate first date.
	 * @param endDate last date.
	 * @param startIndex the first index.
	 * @param nbOfLoops number of loops to retrieve.
	 * @return a list of Loops
	 */
	List<LoopDTO> findLoopsByDates(Date startDate, Date endDate, int startIndex, int nbOfLoops);
	
	/**
	 * Add a comment to a Loop.
	 * @param loopUrl loop primary key.
	 * @param commentAuthor user name.
	 * @param content comment
	 * @return a CommentDTO object.
	 */
	CommentDTO addCommentToLoop(String loopUrl, String commentAuthor, String content);
	
	/**
	 * Add Loop to User Favorites.
	 * @param loopUrl loop primary key.
	 * @param userName user name
	 * @return true if add succeeded, false if he already has favorited it.
	 */
	boolean addLoopToUserFavorites(String loopUrl, String userName);
	
	/**
	 * Remove Loop from favorites.
	 * @param loopUrl loop primary key.
	 * @param userName user name
	 * @return true if removed succeeded
	 */
	boolean removeLoopFromUserFavorites(String loopUrl, String userName);
	
}
